<% taxonomy = parent_resource %>
<% taxon = child_resource %>


<div class="sortable-tree-item-row d-flex align-items-center w-100 rounded-lg hover-light border" data-controller="row-link">
  <div class="move-handle mr-3 ml-2">
    <%= icon('grip-vertical', class: 'rounded hover-gray p-2') %>
  </div>

  <div class="flex-grow-1 cursor-pointer" data-action="click->row-link#openLink">
    <div class="d-flex align-items-center overflow-hidden w-100 <% if taxon.square_image&.attached? || taxon.image&.attached? %>py-2<% else %>py-3<% end %>">
      <% if taxon.square_image&.attached? && taxon.square_image.variable? %>
        <%= spree_image_tag(taxon.square_image, class: 'rounded mr-3', width: 48, height: 48, loading: :lazy) %>
      <% elsif taxon.image&.attached? && taxon.image.variable? %>
        <%= spree_image_tag(taxon.image, class: 'rounded mr-3', width: 48, height: 48, loading: :lazy) %>
      <% end %>
      <div class="overflow-hidden">
        <%= taxon.name %>
      </div>
    </div>
  </div>

  <div class="overflow-hidden text-muted font-size-sm ml-auto">
    <% if taxon.classifications.count > 0 %>
      <%= pluralize(taxon.classifications.count, Spree.t(:product)) %>
    <% end %>
  </div>

  <div class="d-flex align-items-center px-3 ml-3 gap-2">
    <%= link_to_edit(taxon, url: spree.edit_admin_taxonomy_taxon_path(taxonomy, taxon.id), data: { row_link_target: :link, turbo_frame: '_top' }) if can?(:edit, taxon) %>

    <%= dropdown class: 'h-100' do %>
      <%= dropdown_toggle class: 'btn-sm px-1 h-100' do %>
        <%= icon('dots-vertical', class: 'mr-0') %>
      <% end %>
      <%= dropdown_menu do %>
        <% if can?(:create, Spree::Taxon) %>
          <%= link_to_with_icon 'plus', Spree.t(:new_nested_taxon), spree.new_admin_taxonomy_taxon_path(taxonomy, taxon: { parent_id: taxon.id }), class: 'dropdown-item' %>
          <div class="dropdown-divider"></div>
        <% end %>
        <%= link_to_delete(taxon, icon: 'trash', url: spree.admin_taxonomy_taxon_path(taxonomy, taxon.id), class: 'dropdown-item btn-danger') if can?(:destroy, taxon) %>
      <% end %>
    <% end %>
  </div>
</div>

